<%--
  Created by IntelliJ IDEA.
  User: LiuXiaoChuan
  Date: 2022/5/17
  Time: 9:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>文件管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery-3.5.1.min.js"></script>

    <script>
        // var util;
        layui.use(['table','util','jquery','layer','form'],function () {
            var table = layui.table,util=layui.util,$=layui.jquery,layer=layui.layer,form=layui.form;

            form.verify({
                v_pass:[
                    /^[\S]{10,500}$/,
                    '长度需要在10-500之间，并且不能有空格'
                ],

            });
            //监听工具栏的按钮  删除
            table.on('tool(demo)',function (res) {
                var row = res.data; //获取当前数据（点哪一行就是哪一行）
                var event = res.event;//获取点的是哪个按钮
                // alert(event);
                var docId = row.docId;
                if(event=='del'){
                    //把id传到后台去删除
                    // alert(row.empId); 弹出要删除的ID
                    layer.confirm('是否删除该条数据？',{
                        btn:['确定','取消']
                    },function () {//确定的回调函数
                        // alert(row.empId);测试是否进入
                        $.post("${pageContext.request.contextPath}/et/dcdel",{docId:docId},function (data) {
                            layer.msg(data.msg);  //使用消息层 显示删除结果
                            //重新加载table
                            table.reload('tableData',{
                                url:"${pageContext.request.contextPath}/et/listdc"
                            });

                        },"json");
                    });
                }else if (event=='dclist'){ //如果是下载
                    window.location="${pageContext.request.contextPath}/et/dclist?docId="+docId;
                }

            });

            //监听form表单提交  模糊查询  查看全部按钮
            form.on('submit(shuax-btn)',function (d) {
                location.reload("titleEt");//重新加载父页面表格
            });


            //监听提交
            form.on('submit(formBtn)', function () {
                var formData = new FormData($("#form1")[0]);
                $.ajax({
                    url:'${pageContext.request.contextPath}/et/dcadd',
                    type : 'POST',
                    data : formData,
                    cache: false,
                    async: false,
                    processData : false,  //必须false才会避开jQuery对 formdata 的默认处理
                    contentType : false,  //必须false才会自动加上正确的Content-Type
                    mimeType:"multipart/form-data",
                    success:function(data){
                        layer.msg('添加成功！',{icon:6,offset:"auto",time:2000});//提示框
                        setTimeout(function(){
                            window.location.reload();//重新加载父页面表格

                        }, 2100);

                    }
                });
                return false;
            });

            //    转载table
            var tabBoss = table.render({
                elem:'#tableData',//指定id选择器
                cols:[[
                    {field:'docId',title:'编号',align:'center'},
                    {field:'docName',title:'资料名称',align:'center'},

                    {field:'optime',title:'上传时间',align:'center',templet:function(d){
                                    return util.toDateString(d.workday,'yyyy年MM月dd日'
                                    )}},
                    {field:'remark',title:'备注 ',align:'center'},
                    {field:'empName',title:'上传人',align:'center'},

                    {toolbar:'#tools',title:'操作',align:'center',fixed:'right'}
                ]],
                url:'${pageContext.request.contextPath}/et/listdc',//请求路径
                method:'post',//请求方法
                page:true,//显示分页主键
                limits:[10,20,25,30],//切换每页行数
                limit:10,//默认的没页行数
                loading:true,//数据加载效果样式

            });

        });
    </script>
</head>
<body><br/>
<h1 style="font-weight:bold;"></h1>
<button class="layui-btn layui-btn-normal layui-icon layui-icon-refresh" lay-submit lay-filter="shuax-btn">刷新</button>

<table class="layui-table" id="tableData" lay-filter="demo" lay-size="sm"></table>
<div>
    <form class="layui-form"  id="form1"  lay-filter="form1" enctype="multipart/form-data">

        <input type="hidden" name="empId" value="${sessionScope.emp.empId}"/>

        <div class="layui-form-item">
            <div class="layui-form-item" style="margin-left: 80px">
                <label class="layui-form-label" >上传文件：</label>
                <div class="layui-input-inline">
                    <input type="file" name="fileface"  lay-verify="required">
                </div>
                <%--        提交--%>
                <div style="margin-left: 45%">
                    <button class="layui-btn layui-btn-normal layui-icon layui-icon-ok-circle"
                            lay-submit lay-filter="formBtn">提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary layui-icon layui-icon-rate-half">重置</button>
                </div>
            </div>

        </div>
        <%--  备注--%>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 150px">备注：</label>
            <div class="layui-input-inline">
                <textarea name="remark" class="layui-input" style="width: 200px;height: 100px" placeholder="备注字数10-500字" lay-verify="v_pass"></textarea>
            </div>

        </div>
    </form>
</div>

            <%--    定义工具栏--%>
<script type="text/html" id="tools">
    <a class="layui-btn layui-btn-sm layui-btn-danger layui-icon layui-icon-delete" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-sm layui-btn-danger layui-icon layui-icon-link" lay-event="dclist">文件下载</a>

</script>

</body>
</html>
